import { loginAPI ,getProfileAPI} from '@/api/user'
export default {
  namespaced: true,
  state: {
     token: '',
     profile:{}
  },
  mutations: {
    setToken(state, token) {
      state.token = token
    },
    setProfile(state, profile) {
      state.profile = profile
    },
    clearUserInfo(state) {
      state.token = ''
      state.profile = {}   // 清空用户信息
    }

  },
  actions: {
    async logintoken(ctx,{ username, password }) {
        console.log(username, password)
        let res = await loginAPI({ username, password })
        ctx.commit('setToken', res.data.token)
    },
    async getProfile(ctx) {
      let res = await getProfileAPI()
      ctx.commit('setProfile', res.data)
      return res.data.permissions
    }
  }
} 
